import { IRouterSet, withAuthorize, withParameters } from '../widgets/RouterView'
import Join from '../pages/Join'
import { Redirect } from 'react-router-dom'
import React from 'react'
import Home from '../pages/Home'
import Series from '../pages/Series'
import Goods from '../pages/Goods'

const routers: IRouterSet = {
    home: {
        name: 'Home',
        component: Home
    },
    join: {
        name: 'Join',
        component: Join
    },
    series: {
        name: 'Series',
        component: withParameters('/series/{seriesId}', Series)
    },
    goods: {
        name: 'Goods',
        component: withParameters('/goods/{goodsId}', Goods)
    }
}

function CheckAuth(component: any) {
    return withAuthorize(
        () => localStorage.getItem('token') as any,
        // 你也可以直接重定向到某个页面
        // <Redirect to="/home/welcome"></Redirect>
        <Redirect to="/home" />
    )(component)
}

export default routers
